#include<bits/stdc++.h>
using namespace std;
int ans,n,t,x;
bool f[1000005];

signed main()
{
 //   freopen("color.in","r",stdin);
 //   freopen("color.out","w",stdout);
    cin >> t;
    while(t--)
    {
        memset(f,false,sizeof f);
        ans = 0;
        cin >> n;
        while(n--)
        {
            cin >> x;
            if(!f[x]) f[x] = true;
            else ans += x;
        }
        cout << ans << endl;
    }
    return 0;
}
